package com.fuego.creditsystemcommodity.controller;

import com.fuego.creditsystemcommodity.service.IHouseInfoService;
import com.fuego.creditsystemcommodity.service.IHouseService;
import jakarta.annotation.Resource;
import org.example.dto.Result;
import org.example.entity.House;
import org.springframework.web.bind.annotation.*;




@RestController
@RequestMapping("/house")
public class HouseController {

    @Resource
    private IHouseService houseService;

    @Resource
    private IHouseInfoService houseInfoService;


    @PostMapping
    public Result addHouse(@RequestBody House house) {
        houseService.save(house);
        return Result.ok(house.getId());
    }


    @PostMapping("houseInfo")
    public Result addHouseInfo(@RequestBody House house) {
        houseService.addHouseInfo(house);
        return Result.ok(house.getId());
    }


    @GetMapping("/list/{ownerId}")
    public Result queryHouseOfOwner(@PathVariable("ownerId") Long ownerId) {
        return houseService.queryHouseOfOwner(ownerId);
    }

    @GetMapping("/list/allHouse")
    public Result queryAllHouse() {
        return houseService.queryAllHouse();
    }

    @GetMapping("/house/{houseId}")
    public Result queryHouseById(@PathVariable("houseId") Long houseId) {

        return houseService.queryHouseById(houseId);
    }

    @GetMapping("/houseInfo/{houseId}")
    public Result queryHouseInfoById(@PathVariable("houseId") Long houseId) {

        return houseInfoService.queryHouseInfoById(houseId);
    }


    @GetMapping("/list/pageHouse")
    public Result pageHouse(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "12") Integer pageSize
    ){
        return houseService.pageHouse(page, pageSize);
    }

    @GetMapping("/search/{houseName}")
    public Result searchGood(@PathVariable("houseName") String houseName) {

        return houseService.searchHouse(houseName);
    }
}

